package up.android.map;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import up.android.R;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


public class MapTestActivity extends MapActivity implements LocationListener {

	private MapView mapView;
	private List<Overlay> mapOverlays;
	private ExampleItemizedOverlay itemizedOverlay;
	private LocationManager locationManager;
	
	@Override
	protected boolean isRouteDisplayed() {
	    return false;
	}
	
	@Override
	protected void onCreate(Bundle icicle) {
		// TODO Auto-generated method stub
		super.onCreate(icicle);
		setContentView(R.layout.map);
		
		mapView = (MapView) findViewById(R.id.mapview);
		mapView.setBuiltInZoomControls(true);
		
		mapOverlays = mapView.getOverlays();
		Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
		itemizedOverlay = new ExampleItemizedOverlay(drawable);
		
		locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
		locationManager.requestLocationUpdates
		(android.location.LocationManager.GPS_PROVIDER,15000,0,this);

	}
	
	public void onLocationChanged(Location loc) {
		GeoPoint point = new GeoPoint((int)(loc.getLatitude()*1000000),(int)(loc.getLongitude()*1000000));
		OverlayItem overlayitem = new OverlayItem(point, "", "");
		
		itemizedOverlay.addOverlay(overlayitem);
		mapOverlays.add(itemizedOverlay);

		mapView.refreshDrawableState();
		
		locationManager.removeUpdates(this);
		
	}

	public void onProviderDisabled(String arg0) {
		// TODO Auto-generated method stub
		
	}

	public void onProviderEnabled(String arg0) {
		// TODO Auto-generated method stub
		
	}

	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
		// TODO Auto-generated method stub
		
	}
	
}
